"""
AI分析  管理路由
负责AI分析的请求和响应
"""

from typing import List, Dict, Optional
import tempfile
from pathlib import Path
from fastapi import APIRouter, File, UploadFile, HTTPException
from starlette.responses import JSONResponse, FileResponse
from loguru import logger

from models.schemas import AnalysisRequest, AnalysisResponse, StatusCode

# 新增：asyncio 和任务相关依赖
import asyncio
import uuid
import time
from managers.util import get_ai_result


ai_router = APIRouter()
    
@ai_router.post("/ai/single", response_model=AnalysisResponse)
async def request_ai_analysis(request: AnalysisRequest) -> AnalysisResponse:
    start_time = time.time()
    result = await get_ai_result(request.dicom_uid, request.img_data, request.seg_data, request.dsa_position)
    processing_time = time.time() - start_time
    response = AnalysisResponse(
        dicom_uid=request.dicom_uid,
        processing_time=processing_time,
        result=result,
    )
    return response
